/**
 * 
 */
$(document).ready(function() {
		var investRemoteTrans = new Helper.RemoteTrans({
			url : Helper.basePath + "/investInfo/doInvest.htm",
			isAsync : false,
			onSuccess : function(jsonData) {
				if (jsonData.code != "000") {
					$("#invest_err_msg").text(jsonData.message);
					$("#invest_err_msg").show();
				} else {
					if(jsonData.returnObject){
						var direc_page = window.open("", "direc_page");
						direc_page.document.write(jsonData.returnValue.orderFormContent);
					}else{
						alert(jsonData.returnValue.orderFormContent);
						location.reload(true);
					}
				}
			},
			onError : function(data) {
				$("#invest_err_msg").text(data.message);
				Helper.message(data.message);
			}
		});
		//点击投资
		$("#investBtn").click(function() {
			var money = $.trim($("#investMoney").val());
			if (money == null || money == "") {
				alert("请输入投资金额");
				return;
			}
			if (isNaN(money)) {
				alert("投资金额必须为数字");
				return;
			}
			var re = /^[1-9]\d*$/;
			if (!re.test(money)) {
		        alert("投资金额必须为正整数!");
		        return;
		    }
			if(window.confirm('您确定要投资操作吗？')){
				investRemoteTrans.params = {borrowInfoId:$("#borrowInfoId").val().trim(),investMoney:$("#investMoney").val()};
				investRemoteTrans.send();
			}
		});
		//
		//筹款倒计时
		var year = $("#bidStopyear").val();
		var month = $("#bidStopmonth").val();
		var day = $("#bidStopday").val();
		var hour = $("#bidStophour").val();
		var min = $("#bidStopmin").val();
		var sec = $("#bidStopss").val();
		window.setInterval(function(){ShowCountDown(year,month,day,hour,min,sec,'countdown_row');}, 1000);//筹款倒计时
		
		//计算预期收益
		$("#investMoney").keyup(function(){
			if ($(this).val() == null || $(this).val() == "") {
				$("#espectMoney").text("");
				return;
			}
			if (isNaN($(this).val())) {
				$("#espectMoney").text("");
				return;
			}
			var re = /^[1-9]\d*$/;
			if (!re.test($(this).val())) {
				$("#espectMoney").text("");
		        return;
		    }
			var money = parseFloat($(this).val());
			var borrowrate = parseFloat($("#borrowRate").val()/100);
			var rewardRate = parseFloat($("#rewardRate").val()/100);
			var borrowDuration = parseFloat($("#borrowDuration").val());
			var durType = $("#durType").val();
			var espectMoney = 0;
			//alert("money:" + money);
			//alert("borrowrate:" + borrowrate);
			//alert("rewardRate:" + rewardRate);
			//alert("borrowDuration:" + borrowDuration);
			if (durType == "MONTH") {
				espectMoney = money * (borrowrate+rewardRate) / 12 * borrowDuration;
			} else if (durType == "DAY") {
				espectMoney = money * (borrowrate+rewardRate) / 365 * borrowDuration;
			}
			$("#espectMoney").text(espectMoney.toFixed(2));
		});
});